package com.appistry.management.domain.impl;

import java.io.InputStream;

import com.appistry.api.rest.domain.RestResponse;
import com.appistry.management.FabricFile;
import com.appistry.management.domain.AbstractRestDomainObject;
import com.appistry.management.exception.FabricManagerException;
import com.appistry.management.rest.RestFabricManager;

public class FabricFileImpl extends AbstractRestDomainObject implements FabricFile{
	private RestFabricManager restFabricManager;
	private String name;
	
	public FabricFileImpl(RestFabricManager restFabricManager, String name) {
		this.restFabricManager = restFabricManager;
		this.name = name;
	}

	public boolean delete() throws FabricManagerException {
		try {
			RestResponse restResponse = restFabricManager.deleteFileManagement(name);
			checkForErrors(restResponse);

			return true;
		} catch (Exception e) {
			throw new FabricManagerException(e);
		}
	}

	public InputStream getInputStream() throws FabricManagerException {
		try {
			RestResponse restResponse = restFabricManager.getFileManagement(name);
			checkForErrors(restResponse);

			return restResponse.getBodyAsStream();
		} catch (Exception e) {
			throw new FabricManagerException(e);
		}
	}

	public String getName() {
		return name;
	}
	

}
